package com.power.structure.queue;

/**
 * @description:
 * @author: jiangnan
 * @time: 2021/6/13 7:24 下午
 */
public class SingleQueue {
    private int CAPACITY = 10;
    private int[] data;
    private int size;

    public SingleQueue() {
        data = new int[10];
    }

    public void enque(int element) {
        if (isFull()) {
            throw new IllegalStateException("队列满啦");
        }
        data[size++] = element;
    }

    public int deque() {
        if (isEmpty()) {
            throw new IllegalStateException("队列空啦");
        }
       // int index = size-1;
        return data[--size];
    }


    public boolean isEmpty() {
        if (size == 0) {
            return true;
        }
        return false;
    }

    public boolean isFull() {
        if (size == CAPACITY) {
            return true;
        }
        return false;
    }

    public void display() {
        for (int j = size - 1; j >= 0; j--) {
            System.out.print(" " + data[j]);
        }
        System.out.println();
    }
    public static void main(String[] args) {
        SingleQueue queue = new SingleQueue();
        for (int i = 0; i < 10; i++) {
            queue.enque(i);
        }

        queue.deque();
        queue.deque();
        queue.deque();
        queue.display();
    }
}

